import java.io.IOException;
import java.net.DatagramSocket;
import java.net.Inet4Address;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
import java.util.Arrays;

import junit.framework.TestCase;

public class RouterProtocolTest extends TestCase {
	
	DatagramSocket socket1 = null, socket2 = null;
	int port1 = 9999, port2 = 9998;
	byte id1 = (byte)1, id2 = (byte)2;
	int[] distanceVector;
	private InetSocketAddress address1;
	private InetSocketAddress address2;

	public static void main(String[] args) {
		junit.swingui.TestRunner.run(RouterProtocolTest.class);
	}

	public RouterProtocolTest(String name) {
		super(name);
	}

	protected void setUp() throws Exception {
		super.setUp();
		this.socket1 = new DatagramSocket( port1 );
		this.address1 = new InetSocketAddress( "127.0.0.1", port1 ); 
		this.socket2 = new DatagramSocket( port2 );
		this.address2 = new InetSocketAddress( "127.0.0.1", port2 );
		distanceVector = new int[16];
		Arrays.fill(distanceVector, 65535 );
	}

	protected void tearDown() throws Exception {
		super.tearDown();
		this.socket1.close();
		this.socket2.close();
	}

	/*
	 * Test method for 'RouterProtocol.sendRouterProtocolPacket(RouterProtocolPacket, DatagramSocket, SocketAddress)'
	 */
	public void testSendReceiveRouterProtocolPacket() throws IOException {
		RouterProtocolPacket sentPacket = new RouterProtocolPacket( id1, distanceVector );
		
		RouterProtocol.sendRouterProtocolPacket( sentPacket, socket1, address2);
		RouterProtocolPacket receivedPacket = RouterProtocol.receivePacket( socket2 );
		assertEquals( sentPacket, receivedPacket );
	}

}
